<template>
  <div class="app-container">
    <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" @export="handleExport">
    </wms-form>
    <wms-table class="table-click" :loading="loading" :data-list="deliverDetailsList" :column="column"
      :pageInfo="queryParams" @get-list="getList" @row-click="handleRowClick" />
    <deliver-register v-if="showRegister" v-model="showRegister" :deliver-info="deliverInfo" @refresh="getList" />
  </div>
</template>

<script setup name="register_wip">
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import DeliverRegister from '../ibWipRegister/deliverRegister/index.vue'
import { listDeliverDetails } from "@/api/wms/deliverDetails";
import { data, column, formList } from './index.js'
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);

let showRegister = ref(false)
let deliverInfo = reactive({
  deliverDetailId: null,
  rcvNo: null,
  zoneId: 301
})

const deliverDetailsList = ref([]);
const loading = ref(true);

// ###相关方法###
// 处理行点击
const handleRowClick = (row) => {
  console.log('点击预约单行', row)
  showRegister.value = true
  deliverInfo.deliverDetailId = row.deliverDetailId
  deliverInfo.rcvNo = row.rcvNo
}

/** 查询入库明细单列表 */
function getList() {
  loading.value = true;
  listDeliverDetails(proxy.addDateRange(queryParams, queryParams.dateRange)).then(response => {
    deliverDetailsList.value = response.rows;
    queryParams.total = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParams.dateRange = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('wms/deliverDetails/export', {
    ...queryParams
  }, `送货单_${new Date().getTime()}.xlsx`)
}

getList();
</script>
